define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

		$scope.form.father_id=params.father_id;
		if(params.fk_unit!='undefined'){
			$scope.form.fk_unit=params.fk_unit;
		}

		//查询主校区和分校区
		httpService.post(app.urls.unit_selectSchoolAndAttach,{},function(data){
			if("0000" === data.code){
				$scope.unitList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//查询年级
		httpService.post(app.urls.grade_selectSchoolGrade,{},function(data){
			if("0000" === data.code){
				$scope.gradeList = data.data;
			}else{
				alert(data.msg);
			}
		});
		$scope.saveForm = function(){
			if($scope.formCheck()) {
				httpService.post(app.urls.unit_grade_select,{"fk_unit":$scope.form.fk_unit,"fk_grade":$scope.form.fk_grade},function(data){
					if("0000" === data.code){
						if(data.data.length<=0){
							httpService.post(app.urls.unit_grade_insert,$scope.form,function(data){
								if("0000" === data.code){
									eventBusService.publish("content.page.reload", data);
									eventBusService.publish("modal.page.close", {});
								}else{
									alert(data.msg);
								}
							});
						}else {
							alert("重复添加该年级")
						}
					}else{
						alert(data.msg);
					}
				});
			}
		}
	}}});